package yxy.cherry.battle.module.record;

import yxy.cherry.battle.module.Position;

public enum FighterPosition implements IRecordField {
	FUL("A", 1, FighterSide.LEFT, Position.FU), // 左 前上
	FML("B", 2, FighterSide.LEFT, Position.FM), // 左 前中
	FDL("C", 3, FighterSide.LEFT, Position.FD), // 左 前下
	BUL("D", 4, FighterSide.LEFT, Position.BU), // 左 后上
	BML("E", 5, FighterSide.LEFT, Position.BM), // 左 后中
	BDL("F", 6, FighterSide.LEFT, Position.BD), // 左 后下
	NBL("G", 7, FighterSide.LEFT, null), // 左 神兵
	FUR("H", 8, FighterSide.RIGHT, Position.FU), // 右 前上
	FMR("I", 9, FighterSide.RIGHT, Position.FM), // 右 前中
	FDR("J", 10, FighterSide.RIGHT, Position.FD), // 右 前下
	BUR("K", 11, FighterSide.RIGHT, Position.BU), // 右 后上
	BMR("L", 12, FighterSide.RIGHT, Position.BM), // 右 后中
	BDR("M", 13, FighterSide.RIGHT, Position.BD), // 右 后下
	NBR("N", 14, FighterSide.RIGHT, null), // 右 神兵
	SSL("O", 15, FighterSide.LEFT, null),//左 神兽
	SSR("P", 16, FighterSide.RIGHT, null),//右 神兽
	;

	private String code;
	private int number;
	private FighterSide side;
	private Position position;

	private FighterPosition(String code, int number, FighterSide side, Position position) {
		this.code = code;
		this.number = number;
		this.side = side;
		this.position = position;
	}

	@Override
	public String code() {
//		return code;
		return super.name();
	}

	public int getNumber() {
		return number;
	}

	public FighterSide getSide() {
		return side;
	}

	public Position getPosition() {
		return position;
	}

	static public FighterPosition forNumber(int value) {
		switch (value) {
			case 1:
				return FUL;
			case 2:
				return FML;
			case 3:
				return FDL;
			case 4:
				return BUL;
			case 5:
				return BML;
			case 6:
				return BDL;
			case 7:
				return NBL;
			case 8:
				return FUR;
			case 9:
				return FMR;
			case 10:
				return FDR;
			case 11:
				return BUR;
			case 12:
				return BMR;
			case 13:
				return BDR;
			case 14:
				return NBR;
			case 15:
				return SSL;
			case 16:
				return SSR;
			default:
				return null;
		}
	}

	static public FighterPosition forPosition(Position position, boolean isLeft) {
		switch (position) {
			case BD:
				return isLeft ? BDL : BDR;
			case BM:
				return isLeft ? BML : BMR;
			case BU:
				return isLeft ? BUL : BUR;
			case FD:
				return isLeft ? FDL : FDR;
			case FM:
				return isLeft ? FML : FMR;
			case FU:
				return isLeft ? FUL : FUR;
			case SS:
				return isLeft ? SSL : SSR;
			default:
				return isLeft ? NBL : NBR;
		}
	}

	static public FighterPosition forPosition(Position position, FighterSide side) {
		return forPosition(position, side.equals(FighterSide.LEFT));
	}
}
